//
//  UserManager.m
//  DongChiDaChiProject1
//
//  Created by lanou3g on 15/11/7.
//  Copyright © 2015年 com.lanou3g. All rights reserved.
//

#import "UserManager.h"
#import <AFNetworking.h>


@implementation UserManager

+ (UserManager *)shareUserManagerHandle
{
    static UserManager *userManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        userManager = [[UserManager alloc] init];
    });
    return userManager;
}

// 存储用户名
- (void)saveUserName:(NSString *)userName
{
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    [userDe setValue:userName forKey:@"userName"];
    // 保存
    [userDe synchronize];
}

// 提取用户名
- (NSString *)getUserName
{
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    return [userDe valueForKey:@"userName"];
}

// 保存登陆状态
- (void)saveIsLogined:(NSString *)isLogined
{
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    [userDe setValue:isLogined forKey:@"isLogined"];
    // 保存
    [userDe synchronize];
}

// 提取登陆状态
- (NSString *)getIsLogined
{
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    
    return [userDe valueForKey:@"isLogined"];
}

// 存储网络状态
- (void)saveNet:(NSString *)isNet
{
    NSUserDefaults *userDe = [NSUserDefaults standardUserDefaults];
    [userDe setValue:isNet forKey:@"isNet"];
    // 保存
    [userDe synchronize];
}

// 提取网络状态
- (NSString *)getNet
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    return [user valueForKey:@"isNet"];
}


// 判断网络是否连接
- (NSInteger)judgeTheNet
{
    // AFNetworkReachabilityStatusUnknown          = -1, // 不可知
    //        AFNetworkReachabilityStatusNotReachable     = 0, // 无网络
    //        AFNetworkReachabilityStatusReachableViaWWAN = 1, // 2d或者3d
    //        AFNetworkReachabilityStatusReachableViaWiFi = 2, // wifi
    __block NSInteger number;
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    // 开启检测网络状态
    [manager startMonitoring];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        number = (NSInteger)status;
    }];
    return number;
}

@end
